package com.dhcc.kafka.sender;
import java.util.Date;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dhcc.kafka.entity.Message;
import com.google.gson.Gson;

/**
 * 
* <p>标题: KafkaSender.java</p>
* <p>业务描述:KafkaSender</p>
* <p>公司:东华软件股份公司</p>
* <p>版权:dhcc2013</p>
* @author 胡凯
* @date 2019年7月31日
* @version V1.0
 */
@Component
@RestController
@RequestMapping("kafka")
public class KafkaSender {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;
    
    @RequestMapping("send")
    public void send() {
        Message message = new Message();
        message.setId(System.currentTimeMillis());
        message.setMsg(UUID.randomUUID().toString());
        message.setTime(new Date());
        kafkaTemplate.send("kafka_kill", new Gson().toJson(message));
    }

}